<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>823680621@qq.com</title>
    <style>
        #canvas{
            border: 1px solid #000000;
            display: block;
            margin: 50px auto;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="800" height="400">
        当前浏览器不支持canvas
    </canvas>
</body>
<script>
    let canvas = document.getElementById('canvas')
    let context = canvas.getContext('2d')
    context.rect(50,20,200,120)
    context.stroke()

    context.clip()//裁切

    context.fillStyle="red"
    context.fillRect(0,0,150,100)

    context.fillStyle="green"
    context.fillRect(100,0,150,100)


</script>
</html>